/*
 * This file is part of aKoustiK.

 * aKoustiK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * aKoustiK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with aKoustiK.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SEEKWIDGET_H
#define SEEKWIDGET_H

#include <QtCore/QTime>
#include <QtGui/QLabel>
#include <QtGui/QSlider>
#include <QtGui/QWidget>

#include <player.h>

class SeekWidget : public QWidget {
    Q_OBJECT

public:
    SeekWidget(QWidget* parent);
    ~SeekWidget();

private:

    // fields:
    /** Internal instance of formatter to format text for time indication labels. */
    QTime timeFormatter;
    Player* player;
    QSlider* seekSlider;
    QLabel* currentLabel;
    QLabel* remainingLabel;
    /**
      Flag that indicates if user is controlling slider right now.
      If this flag is true - slider value should not be changed by tick().
      It's set to false in constructor. sliderPressed() slot set's it to true. seekSlider tracking
      is disabled, so sliderValueChanged(int) slot will be invoked only when user will release slider,
      and it will set this flag back to false.
      */
    bool userHoldsSlider;

    // methods:
    /** Actual method of time formatting. */
    QString formatTime(qint64 time);

private slots:
    /** Slot that updates seekSlider if userHoldsSlider is set to false, and updates both labels. */
    void updateEverything();
    void seekableChanged(bool isSeekable);
    void totalTimeChanged(qint64 newTotalTime);
    void tick(qint64 time);
    void sliderPressed();
    void sliderValueChanged(int value);
};

#endif
